source("../src/definitions.R")
## Loading required package: statnet.common
##
## Attaching package: 'statnet.common'
## The following object is masked from 'package:base':
##
## order
## Loading required package: network
## network: Classes for Relational Data
## Version 1.13.0.1 created on 2015-08-31.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
## Mark S. Handcock, University of California -- Los Angeles
## David R. Hunter, Penn State University
## Martina Morris, University of Washington
## Skye Bender-deMoll, University of Washington
## For citation information, type citation("network").
## Type help("network-package") to get started.
## sna: Tools for Social Network Analysis
## Version 2.4 created on 2016-07-23.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
## For citation information, type citation("sna").
## Type help(package="sna") to get started.
if(exists("seed"))
{
seed <- seed + 1
} else {
seed <- 100
}
cat("Using random seed: ",seed,"\n")
## Using random seed: 100
set.seed(seed)
This builds on model 10 by doing simple search through neighbor models and integrating both the growing and culling process. On each reconstruction round, it picks a single node to add, evaluates whether the model with the node improves fit 50%, and adds it if it does. It also culls points using the sim9 model.
Sim12 advances over this by, rather than picking nodes at random, picks probabilistically based on the correlation with the outcome variable.
To set up an environment, you need:
##input nodes and 1 output node.
## there are only 6 relevant nodes, the rest are garbage.
##test 8 is the random contrast condition for the same set-up
##test 9 is a crafted constrast condition.
numnodes<- 20
##learn from.
avals <- runif(numnodes)
##each row represents the outgoing connections from each node
aweights <-array( matrix(rep(0,numnodes^2),numnodes),
dim=list(numnodes,numnodes,1))
aweights[,numnodes,1] <- c(-10,-5,-1,rep(0,numnodes-7),1,5,10,0)
input <- c(rep(T,numnodes-1),F)
output <- !input
visible <- rep(T,numnodes)
coord <- plotMM(aweights[,,1],aweights[,,1],input,output) ##take
data <- generateData(reps=1000,aweights=aweights,avals=avals,iter=10,input=input,noise=noise)
## Using random seed: 101
## [1] "BLOCK 1"
## [1] "10 0.823883000217525 FALSE"
## [1] "BLOCK 2"
## [1] "9 1.15239591662173 FALSE"
## [1] "BLOCK 3"
## [1] "8 1.22490964812371 FALSE"
## [1] "BLOCK 4"
## [1] "5 0.906195362119403 FALSE"
## [1] "BLOCK 5"
## [1] "4 1.04596873872116 FALSE"
## [1] "BLOCK 6"
## [1] "8 1.14394837268181 FALSE"
## [1] "BLOCK 7"
## [1] "8 0.921329153951706 FALSE"
## [1] "BLOCK 8"
## [1] "9 1.10557672273826 FALSE"
## [1] "BLOCK 9"
## [1] "5 0.993273627972482 FALSE"
## [1] "BLOCK 10"
## [1] "5 1.01762141895369 FALSE"
## [1] "BLOCK 11"
## [1] "8 0.83333345774682 FALSE"
## [1] "BLOCK 12"
## [1] "7 1.19203238369047 FALSE"
## [1] "BLOCK 13"
## [1] "7 0.954358783890903 FALSE"
## [1] "BLOCK 14"
## [1] "5 0.945248177798562 FALSE"
## [1] "BLOCK 15"
## [1] "1 0.58837340912869 FALSE"
## [1] "Adding node 1"
## [1] "BLOCK 16"
## [1] "5 1.50522741147992 FALSE"
## [1] "BLOCK 17"
## [1] "10 0.836061708491672 TRUE"
## [1] "BLOCK 18"
## [1] "10 1.06396929802354 FALSE"
## [1] "BLOCK 19"
## [1] "16 1.19253168227713 TRUE"
## [1] "BLOCK 20"
## [1] "10 1.83033081471021 FALSE"
## [1] "BLOCK 21"
## [1] "9 1.26715014087743 TRUE"
## [1] "BLOCK 22"
## [1] "11 1.0793949496614 TRUE"
## [1] "BLOCK 23"
## [1] "10 1.0837128023946 TRUE"
## [1] "BLOCK 24"
## [1] "14 0.918216555488569 FALSE"
## [1] "BLOCK 25"
## [1] "6 1.0031212354365 TRUE"
## [1] "BLOCK 26"
## [1] "9 0.892036079626979 TRUE"
## [1] "BLOCK 27"
## [1] "9 1.32240321094541 TRUE"
## [1] "BLOCK 28"
## [1] "10 1.11323404537301 TRUE"
## [1] "BLOCK 29"
## [1] "13 1.07537683883997 TRUE"
## [1] "BLOCK 30"
## [1] "15 1.25412679611538 TRUE"
## [1] "BLOCK 31"
## [1] "4 1.50106090126778 TRUE"
## [1] "BLOCK 32"
## [1] "16 1.09554674001392 TRUE"
## [1] "BLOCK 33"
## [1] "16 1.23864394733954 TRUE"
## [1] "BLOCK 34"
## [1] "8 0.972901964799553 TRUE"
## [1] "BLOCK 35"
## [1] "11 1.22349975367131 TRUE"
## [1] "BLOCK 36"
## [1] "13 1.04120490491632 TRUE"
## [1] "BLOCK 37"
## [1] "8 0.723797273240265 TRUE"
## [1] "BLOCK 38"
## [1] "7 1.29122140354626 TRUE"
## [1] "BLOCK 39"
## [1] "15 1.19574983214184 TRUE"
## [1] "BLOCK 40"
## [1] "9 1.11118236057326 TRUE"
## [1] "BLOCK 41"
## [1] "5 1.42336655980581 FALSE"
## [1] "BLOCK 42"
## [1] "13 1.07317005280706 TRUE"
## [1] "BLOCK 43"
## [1] "8 1.03344640846356 TRUE"
## [1] "BLOCK 44"
## [1] "7 0.964558224136076 TRUE"
## [1] "BLOCK 45"
## [1] "12 1.19552633052419 TRUE"
## [1] "BLOCK 46"
## [1] "7 1.23275573046214 TRUE"
## [1] "BLOCK 47"
## [1] "6 1.26870538633103 TRUE"
## [1] "BLOCK 48"
## [1] "7 1.18558816897252 TRUE"
## [1] "BLOCK 49"
## [1] "12 1.03294827419281 TRUE"
## [1] "BLOCK 50"
## [1] "10 1.07038978605001 TRUE"
par(mfrow=c(1,3),mar=c(3,4,2,0))
image(as.matrix(hweights[,numnodes,]),col=brewer.pal(11,"RdYlGn"))
plotWeights(hweights,hframe,output,main=paste("Trial:",trial))
lerr <- apply(abs(learningerror),3, mean)
plot(lerr,col="grey30",main="Error over time",ylab="Mean absolute error",xlab="Learning round")
points(lowess(lerr,f=.2),lty=1,type='l',lwd=4,col="red")